﻿using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace OpenCompiler.Scanning.Tests.Specs_for_scanner
{
	[TestClass]
	public class When_tokenizing
	{
		[TestMethod]
		public void Line_numbers_are_generated_correctly()
		{
			const string sourceCode = "text\ntext\ntext";
			var tokens = TokenTestHelper.TokenizeWithoutEOF(sourceCode);
			Assert.AreEqual(5,tokens.Count);

			Assert.AreEqual(1, tokens[0].Location.Line);
			Assert.AreEqual(2, tokens[2].Location.Line);
			Assert.AreEqual(3, tokens[4].Location.Line);
		}

		[TestMethod]
		public void Column_numbers_are_generated_correctly()
		{
			const string sourceCode = "text\n text\n  text";
			var tokens = TokenTestHelper.TokenizeWithoutEOF(sourceCode);
			Assert.AreEqual(5, tokens.Count);

			Assert.AreEqual(1, tokens[0].Column);
			Assert.AreEqual(5, tokens[1].Column);
			Assert.AreEqual(2, tokens[2].Column);
			Assert.AreEqual(6, tokens[3].Column);
			Assert.AreEqual(3, tokens[4].Column);
		}

		[TestMethod]
		public void Column_numbers_are_generated_correctly_when_using_tabs()
		{
			const string sourceCode = "text\n\ttext\n\t\ttext";
			var tokens = TokenTestHelper.TokenizeWithoutEOF(sourceCode);
			Assert.AreEqual(5, tokens.Count);

			Assert.AreEqual(1,tokens[0].Column);
			Assert.AreEqual(1 + Indentation.TabSize,tokens[2].Column);
			Assert.AreEqual(1 + (Indentation.TabSize*2), tokens[4].Column);
			
		}
	}
}